package com.ethink.platform.controller.system;

import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.system.api.SystemRoleFacade;
import com.ethink.system.api.info.SystemRoleInfo;
import com.ethink.system.api.request.SystemRoleAddRequest;
import com.ethink.system.api.request.SystemRoleQueryRequest;
import com.ethink.system.api.request.SystemRoleUpdateRequest;
import com.ethink.system.api.response.SystemRoleDetailResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统角色表 Controller
 *
 * @author default
 * @date 2022-09-27
 */
@Tag(name = "SystemRoleController", description = "系统角色表 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/system-service")
public class SystemRoleController extends BaseController {

    @Autowired
    private SystemRoleFacade systemRoleFacade;

    @Operation(summary = "分页查询")
    @GetMapping("/systemRole/query")
    public CommonResponse<List<SystemRoleInfo>> querySystemRole(SystemRoleQueryRequest request) {
        return succeedWithPage(systemRoleFacade.querySystemRole(request));
    }

    @Operation(summary = "详情查询")
    @GetMapping("/systemRole/get/{systemRoleId}")
    public CommonResponse<SystemRoleDetailResponse> getSystemRoleById(@PathVariable("systemRoleId") Long systemRoleId) {
        return succeedWith(systemRoleFacade.getSystemRoleById(systemRoleId));
    }

    @Operation(summary = "查询所有")
    @GetMapping("/systemRole/list")
    public CommonResponse<List<SystemRoleInfo>> listSystemRole(SystemRoleQueryRequest request) {
        return succeedWith(systemRoleFacade.listSystemRole(request));
    }

    @Operation(summary = "新增")
    @PostMapping("/systemRole/add")
    public CommonResponse addSystemRole(@RequestBody SystemRoleAddRequest request) {
        systemRoleFacade.addSystemRole(request);
        return succeed();
    }

    @Operation(summary = "更新")
    @PostMapping("/systemRole/update")
    public CommonResponse updateSystemRole(@RequestBody SystemRoleUpdateRequest request) {
        systemRoleFacade.updateSystemRole(request);
        return succeed();
    }

    @Operation(summary = "删除")
    @PostMapping("/systemRole/delete/{systemRoleId}")
    public CommonResponse deleteSystemRole(@PathVariable("systemRoleId") Long systemRoleId) {
        systemRoleFacade.deleteSystemRole(systemRoleId);
        return succeed();
    }

}